/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package unc.pds.facets;

import java.net.URLEncoder;
import unc.pds.filemodel.FileRemote;

/**
 *
 * @author Mikhail
 */
public class FileFacet implements Facet {
    private FileRemote file;
    private boolean isOwn;
    public FileFacet(FileRemote file, boolean isOwn) {
        this.file = file;
        this.isOwn = isOwn;
    }
    public String draw() throws Exception {
        String result = "";
        result += "<p><h4>"+file.getName()+" - "+file.getAuthor().getNickname()+"</h4></p>\n";
        result += "<p><i>Создано "+DateFormatter.format(file.getDate())+"</i></p>";
        result += "<p><a href=\"index.jsp?id="+file.getParent().getKey()+"\"><img src=\"img/back.png\" alt=\"Назад\"/></a>\n";
        result += "<a href=\"download.jsp?id="+file.getKey()+"/"+URLEncoder.encode(file.getName(), "UTF-8")+"\"><img src=\"img/download.png\" alt=\"Загрузить\"/></a>";
        if (isOwn) {
            result += " <a href=\"filesystem-processor.jsp?objid="+file.getKey()+"&action=delete\"><img src=\"img/delete.png\" alt=\"Удалить\"/></a>";
        }
        result += "</p>\n";
        return result;
    }
    public boolean isSide() {
        return false;
    }
}
